/*
Copyright (c) 2006 - 2008  Universitaet Osnabrueck, virtUOS
Authors: Markus Ketterl, Johannes Emden, Nils Schuhmacher, Andreas Rickling

This file is part of virtPresenter.

virtPresenter is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

virtPresenter is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with virtPresenter.  If not, see <http://www.gnu.org/licenses/>.
*/

package virtPresenter.model
{	
	/**
	 * Delivers the timecode in hh:mm:ss for the video time 
	 */
	public class TimeCode {
		
		private var _showHours:Boolean;		
		
		/**
		 * Constructor for TimeCode. 
		 */
		public function TimeCode() {
			_showHours = true;
		}
		
		/**
		 * Setter mehtod if hours should be shown or not
		 * 
		 * @parameter show Boolean
		 */	
		public function showHours(show:Boolean):void {
			_showHours = show;
		}		
		
		/**
		 * Calculates the timecode for the given time in seconds
		 * 
		 * @parameter seconds Time in seconds
		 * 
		 * @return String Timecode as a string wheter in mm:ss or hh:mm:ss
		 */	
		public function getTC(seconds:Number):String {
			
			if(typeof(seconds) != "number")
				return "00:";
			
			var result:String = "";		
			var myTime:Date = new Date(2007, 0, 1 , 0, 0, seconds);		
						
			// hours
			if (_showHours == true) {
					if (myTime.getHours() <10) {
        					result = "0" + myTime.getHours() + ":";
    				}
    				else {
        					result = myTime.getHours() + ":";
   					};
			};
			
			// minutes
			if (myTime.getMinutes() <10) {
        			result += "0" + myTime.getMinutes() + ":";
    		}
    		else {
        			result += myTime.getMinutes() + ":";
   			};			
			
			// seconds
			if (myTime.getSeconds() <10) {
        			result += "0" + myTime.getSeconds();
    		}
    		else {
        			result += myTime.getSeconds();
   			};			
			
		return result;
		}
		
	}
}